<template>
  <div class="app-container">
    <h2>基本信息</h2>
    <el-form ref="userInfo" :model="userInfo" label-width="120px">
      <el-row :gutter="10">
        <el-col :span=6>
          <el-form-item label="姓名">
              <el-input v-model="userInfo.name" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span=6>
          <el-form-item label="工号">
              <el-input v-model="userInfo.jobNumber" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span=6>
          <el-form-item label="性别">
            <el-select style="width:100%" v-model="userInfo.sex" placeholder="请选择" :disabled="true" >
                <el-option value="男"></el-option>
                <el-option value="女"></el-option>
              </el-select>
          </el-form-item>
        </el-col>
        <el-col :span=6 >
          <el-form-item label="学历">
            <el-select style="width:100%" v-model="userInfo.education" placeholder="请选择" :disabled="true" >
              <el-option
                v-for="item in educationEnum"
                :key="item"
                :label="item"
                :value="item">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span=6 >
          <el-form-item label="职业">
            <el-select style="width:100%" v-model="userInfo.job" placeholder="请选择" :disabled="true" >
              <el-option
                v-for="item in jobs"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span=6 >
          <el-form-item label="职称">
            <el-select style="width:100%" v-model="userInfo.jobTitle" placeholder="请选择" :disabled="true" >
              <el-option
                v-for="item in jobTitles"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span=6>
          <el-form-item label="状态">
            <el-select style="width:100%" v-model="userInfo.status" placeholder="请选择" :disabled="true">
              <el-option
                v-for="item in statusEnum"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span=8 >
          <el-form-item label="手机号">
              <el-input v-model="userInfo.phone" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span=8 :offset=4>
          <el-form-item label="身份证号">
              <el-input v-model="userInfo.idCard" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span=8>
          <el-form-item label="入职时间" >
            <el-date-picker :disabled="true" 
              v-model="userInfo.joinTime"
              type="date"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span=8 :offset=4>
          <el-form-item label="在职时长">
              <el-input v-model="userInfo.joinDay" :disabled="true" >
                <template slot="append">天</template>
              </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span=8>
          <el-form-item label="转正时间">
            <el-date-picker
              :disabled="true" 
              v-model="userInfo.realJoinTime"
              type="date"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span=8 :offset=4>
          <el-form-item label="离职时间">
            <el-date-picker
              :disabled="true" 
              v-model="userInfo.leaveTime"
              type="date"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span=8 >
          <el-form-item label="类型">
            <el-select style="width:100%" v-model="userInfo.jobType" placeholder="请选择" :disabled="true" >
              <el-option
                v-for="item in jobTypes"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span=8 :offset=4>
          <el-form-item label="科室">
            <el-select style="width:100%" v-model="userInfo.jobOffice" multiple placeholder="请选择" :disabled="true" >
              <el-option
                v-for="item in jobOffices"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span=8>
          <el-form-item label="挂号费">
            <el-input type="Number" min=0 v-model="userInfo.registerPrice" :disabled="true">
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="职务" >
        <el-tag type="" v-for="(item, index) in userInfo.jobDutyList" :key="index" style="margin: 0 10px">{{
            item.deptName+'——'+item.name
        }}</el-tag>
      </el-form-item>
      <div style="width:100%;border: 2px solid #E4E7ED;padding: 10px;">
        <el-row :gutter="10"  v-for="(deptWorkAddress, index) in userInfo.userDeptAndWorkAddressVOList" :key="index">
          <el-col :span=8>
            <el-form-item label="工作部门" prop="dept" >
              <el-select style="width:100%" v-model="deptWorkAddress.deptId" placeholder="请选择" :disabled="true">
                <el-option
                  v-for="item in depts"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                  >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span=8 :offset=4>
            <el-form-item style="width:100%" label="工作地点" prop="workAddress">
              <el-select v-model="deptWorkAddress.workAddressId" placeholder="请选择" :disabled="true">
                <el-option
                  v-for="item in workAddresses"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </div> 
    </el-form>
    <el-divider></el-divider>
  </div>
</template>

<script>
import { getList as getJobList } from '@/api/job'
import { getList as getWorkAddressList } from '@/api/workAddress'
import { getList as getDeptList } from '@/api/dept'
import { getList as getJobOfficeList } from '@/api/jobOffice'
import { getList as getJobTypeList } from '@/api/jobType'
import { getList as getJobTitleList } from '@/api/jobTitle'

export default {
  filters: {
    statusColorFilter(status) {
      const statusMap = ['success', 'success', 'gray', 'danger']
      return statusMap[status]
    },
    statusNameFilter(status) {
      const statusMap = ['待审批', '待审批', '在职', '离职']
      return statusMap[status]
    }
  },
  data() {
    const validateSex = (rule, value, callback) => {
      if (!value) callback(new Error('请选择姓别')) 
      else callback()
    }

    return {
      list: null,
      listLoading: true,
      commitBtnLoading: false,
      currentPage: 1,
      pageSize: 10,
      total: 0,
      curIndex: -1,
      infoVisible: false,
      formVisible: false,
      userInfo: {},
      form:{},
      formRules: {
        // name: [{ required: true, trigger: 'blur', validator: validateName }],1
      },
      statusEnum: [{id: 1, name: '在职'}, {id: 2, name: '离职'}],
      sexEnum: ["男", "女"],
      jobDutysEnums: [],
      tmpJobDuty: undefined,
      menus: [],
      menusEnum : [],
      menusEnumInfo : [],
      educationEnum: ["专科", "本科", "研究生", "博士生"],
      jobs : [],
      jobTitles: [],
      jobTypes:["中医", "西医"],
      jobOffices: ["内科","外科","耳鼻喉科"],
      depts: [],
      workAddresses: [],
      jobTitleIsDisabled: false,
      jobDutyIsDisabled: false,
      workAddressIsDisabled: false,
    }
  },
  created() {
    
    this.fetchData()
  },
  
  methods: {
    fetchData() {
      
      this.userInfo = JSON.parse(JSON.stringify(this.$store.getters.userInfo))
      this.userInfo.jobOffice = this.userInfo.jobOffice.split(',').map(item => Number(item))
      
      // enums
      getDeptList().then(deptRes=>{
        console.log("depts: ", deptRes.data)
        this.depts = deptRes.data
      })
      getJobList().then(jobRes=>{
        console.log("jobs: ", jobRes.data)
        this.jobs = jobRes.data
      })
      getJobOfficeList().then(jobOfficeRes=>{
        console.log("job office:", jobOfficeRes.data)
        this.jobOffices = jobOfficeRes.data
      })
      getJobTypeList().then(jobTypeRes=>{
        this.jobTypes = jobTypeRes.data
      })
      getWorkAddressList().then(res=> {
        this.workAddresses = res.data
      })
      getJobTitleList().then(res=> {
        console.log("job titles", res.data)
        this.jobTitles = res.data
      })
    },
  }
}
</script>
